<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Notification List</title>
        <style>
            .messagetext{
                font-size: large;
            }
            .messagehighNormal{
                font-size: x-large;
                color: white;
                background-color: #009ea5;
                display:inline-block
            }
            .messagehighAcceptinvite{
                font-size: x-large;
                color: white;
                background-color: #0065a5;
                display:inline-block
            }
            .messagehighGotoEvent{
                font-size: x-large;
                color: white;
                background-color: #c5d731;
                display:inline-block
            }
            .messagehighDeletedEvent{
                font-size: x-large;
                color: white;
                background-color: #008ace;
                display:inline-block
            }
        </style>
    </h:head>
    <h:body>
        <h:panelGrid columns="3" style="width: 100%">
            <h:graphicImage value="/images/Simbolo_Meteocal.png" height="100"></h:graphicImage>
            <h1>Welcome back</h1>
            <p:button outcome="eventCreation" value="Create a new Event" />
        </h:panelGrid>
        <hr/>
        <div style="height: 40px">
            <h1>Notifications</h1>
        </div>
        <h:form id="form">
            <p:dataList id="list" value="#{messageBean.messages}" var="message" type="ordered" itemType="none" paginator="true" rows="10" styleClass="paginated" >
                <f:facet name="header">
                    Message list
                </f:facet>
                <p:commandLink update=":form:detail" oncomplete="PF('MessageDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" style="float:left;margin-right:10px">
                    <f:setPropertyActionListener value="#{message}" target="#{messageBean.selectedMessage}" />
                    <h:outputText value="DESCR, TYPE, #{message.messageID}, #{message.pubblication}"  />
                </p:commandLink>
                <h:outputText value="#{messageBean.intestazione(message)}" styleClass="#{messageBean.getStyle(message)}"/>
            </p:dataList>

            <p:dialog header="Message info" widgetVar="MessageDialog" modal="true" showEffect="blind" hideEffect="explode" resizable="false" onShow="#{messageBean.setPending()}">
                <p:outputPanel id="detail" style="text-align:center;">
                    <p:panelGrid  columns="2" rendered="#{not empty messageBean.selectedMessage}" columnClasses="label,value">
                        
                        <f:facet name="header">
                            <p:graphicImage value="/images/#{messageBean.getImage()}" height="100"/>
                        </f:facet>

                        <h:outputText value="Text: " />
                        <h:outputText value="#{messageBean.selectedMessage.text}" styleClass="messagetext"/>
                        
                        <h:outputText value="Message sent: " />
                        <h:outputText value="#{messageBean.pubblicationDate}" />
                    </p:panelGrid>
                    <p:commandButton value="Accept Invite" action="#{messageBean.accept()}" disabled="#{messageBean.possibleAction(0)}" oncomplete="PF('MessageDialog').hide();"/>
                    <p:commandButton value="Decline Invite" action="#{messageBean.declined()}" disabled="#{messageBean.possibleAction(1)}" oncomplete="PF('MessageDialog').hide();"/>
                    <p:commandButton value="Go to Event"  action="#{messageBean.gotoevent()}" disabled="#{messageBean.possibleAction(2)}" >
                        <f:param name="idevent" value="#{homePageBean.idselected}"/>
                    </p:commandButton>

                    <p:commandButton value="Delete Message" oncomplete="PF('MessageDialog').hide();" disabled="#{messageBean.possibleAction(3)}">
                        <f:ajax listener="#{messageBean.deleteSelected()}" render="list"/>
                    </p:commandButton>
                </p:outputPanel>
            </p:dialog>
        </h:form>
        <hr/>
        <h:panelGrid columns="3" style="width: 100%">
            <p:button outcome="homepage" value="Move back to your page" />

            <p:button outcome="search" value="Search for a user" />
            <h:form>
                <p:commandButton action="#{loginBean.logout()}" value="Logout"/>
            </h:form>
        </h:panelGrid>
    </h:body>
</html>

